package com.myapp.entity.proxy.database;

import java.util.List;

import com.myapp.data.define.BaseBean;
import com.myapp.data.global.Instances;
import com.myapp.db.config.define.DBConfigBean;
import com.myapp.entity.proxy.interfaces.IProxy;

public class DBProxy implements IProxy {

	@Override
	public int insert(BaseBean entity) throws Exception {
		DBConfigBean dbConfigBean = Instances.getDBConfigContainer()
				.getDBConfigBeanByEntity(entity.getClass());
		int back = dbConfigBean.getDao().insert(entity);
		return back;
	}

	@Override
	public <T extends BaseBean> int update(T entity) throws Exception {
		DBConfigBean dbConfigBean = Instances.getDBConfigContainer()
				.getDBConfigBeanByEntity(entity.getClass());
		int back = dbConfigBean.getDao().update(entity);
		return back;
	}

	@Override
	public <T extends BaseBean> int delete(T entity) throws Exception {
		DBConfigBean dbConfigBean = Instances.getDBConfigContainer()
				.getDBConfigBeanByEntity(entity.getClass());
		int back = dbConfigBean.getDao().delete(entity);
		return back;
	}

	@Override
	public <T extends BaseBean> T get(long id, Class<T> clazz) throws Exception {
		DBConfigBean dbConfigBean = Instances.getDBConfigContainer()
				.getDBConfigBeanByEntity(clazz);
		T back = dbConfigBean.getDao().get(id, clazz);
		return back;
	}

	@Override
	public <T extends BaseBean> List<T> findAllByUid(long uid, Class<T> clazz)
			throws Exception {
		DBConfigBean dbConfigBean = Instances.getDBConfigContainer()
				.getDBConfigBeanByEntity(clazz);
		List<T> back = dbConfigBean.getDao().findAllByUid(uid, clazz);
		return back;
	}
}
